
//通用应答
pub fn universal(event: u32) -> String
{
    let json_val = serde_json::json!({
        "event": event + 1000
    });
    //把pack_json序列化成字符串
    let pack_json_str = serde_json::to_string(&json_val).unwrap_or_else(|err| {
        panic!("Failed to serialize JSON: {}, event: {}", err, event + 1000);
    });
    return pack_json_str;
}

//evet20事件应答
pub fn event20(ustate: u8) -> String
{
    let json_val = serde_json::json!({
        "event": 1020,
        "ustate": ustate
    });
    //把pack_json序列化成字符串
    let pack_json_str = serde_json::to_string(&json_val).unwrap_or_else(|err| {
        panic!("Failed to serializeJSON: {}", err);
    });
    return pack_json_str;
}

pub fn event202(progress: u8, devices: u8, result: u8, error: u8) -> String {
    let json_val = serde_json::json!({
        "event": 1202,
        "progress": progress,
        "devices": devices,
        "result": result,
        "error": error
    });
    //把pack_json序列化成字符串
    let pack_json_str = serde_json::to_string(&json_val).unwrap_or_else(|err| {
        panic!("Failed to serializeJSON: {}", err);
    });
    return pack_json_str;
}

pub fn event204(progress: u8, uptype: u8, devices: u8, result: u8, error: u8) -> String {
    let json_val = serde_json::json!({
        "event": 1204,
        "progress": progress,
        "type": uptype,
        "devices": devices,
        "result": result,
        "error": error
    });
    //把pack_json序列化成字符串
    let pack_json_str = serde_json::to_string(&json_val).unwrap_or_else(|err| {
        panic!("Failed to serializeJSON: {}", err);
    });
    return pack_json_str;
}

/*
 exist:0 不存在
 exist:1 存在
*/
pub fn event210(exist: u8) -> String {
    let json_val = serde_json::json!({
        "event": 1210,
        "exist": exist,
    });
    //把pack_json序列化成字符串
    let pack_json_str = serde_json::to_string(&json_val).unwrap_or_else(|err| {
        panic!("Failed to serializeJSON: {}", err);
    });
    return pack_json_str;
}